package curb;

import com.bitsinharmony.recognito.Recognito;
import com.google.common.collect.Maps;
import common.ServerResponse;
import factory.RecogntioFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;
import pojo.VoicePrintView;
import util.HttpClientUtil;
import util.JsonUtil;
import util.PropertiesUtil;

import javax.naming.PartialResultException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2021/4/22.
 */
@Slf4j
public class VoiceController {



    private static Recognito<String> recognito = RecogntioFactory.getRecognito(48000.0f);

    public static void getAllVoicePrint(){
        String result = HttpClientUtil.sendRequest("/voice/getAllVoicePrint.do");

        if (!StringUtils.isNotEmpty(result)){
            throw new NullArgumentException("getAllVoicePrint error, the result");
        }

        ServerResponse serverResponse = JsonUtil.stringToObj(result, ServerResponse.class);
        if (!serverResponse.isSuccess()){
            throw new NullArgumentException("校验未通过，result");
        }

        result = (String) serverResponse.getData();

        //装填
        List<VoicePrintView> voicePrintViewList = JsonUtil.stringToObj(result, ArrayList.class, VoicePrintView.class);
        for (VoicePrintView v : voicePrintViewList) {
            recognito.put(v.getKey(), v.getFeature());
        }
    }

    public static ServerResponse createAttendance(String idNo){
        String result = HttpClientUtil.sendRequest("/attendance/createAttendance.do", idNo);
        if (!StringUtils.isNotEmpty(result)){
            throw new NullArgumentException("createAttendance error, the result");
        }

        return JsonUtil.stringToObj(result, ServerResponse.class);

    }
}
